/**
 *  test_buf.c - Test codes for shared buffer and its functions.
 *               It runs on Windows or Linux.
 *
 *  Copyright (C) 2008  ZhangHu
 *  All rights reserved.
 *  E-MAIL: anmnmnly@gmail.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include "test_buf.h"
#include "kernel/buf.c"


static void test_bufClear_0(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    bufClear(_pBuf);
}



static void test_bufClear_1(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Tested function call */
    bufClear(_pBuf);
}



static void test_bufDel_0(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Tested function call */
    bufDel(_pBuf);
}



static void test_bufDel_1(void) {

    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf  = &_pBuf_0;

    /* Tested function call */
    bufDel(_pBuf);
}



static void test_bufGetUsed_0(void) {
    /* Initializing argument 1 (pBuf) */
    const buf_t *_pBuf = 0;

    /* Tested function call */
    word_t _result = bufGetUsed(_pBuf);
    CU_ASSERT_EQUAL(_result, -1);
}



static void test_bufGetUsed_1(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    const buf_t *_pBuf = &_pBuf_0;

    word_t _result = bufGetUsed(_pBuf);
    CU_ASSERT_EQUAL(_result, -1);
}



static void test_bufInit_0(void) {
    /* Initializing argument 1 (BufSize) */
    uword_t _BufSize = 0;

    /* Tested function call */
    buf_t *_result = bufInit(_BufSize);
    CU_ASSERT_PTR_NULL(_result);
}



static void test_bufInit_1(void) {
    /* Initializing argument 1 (BufSize) */
    uword_t _BufSize = 1;

    /* Tested function call */
    buf_t *_result = bufInit(_BufSize);
    CU_ASSERT_PTR_NOT_NULL(_result);
}



static void test_bufInit_2(void) {
    /* Initializing argument 1 (BufSize) */
    uword_t _BufSize = ~0;

    buf_t *_result = bufInit(_BufSize);
    CU_ASSERT_PTR_NULL(_result);
}




static void test_bufInit_3(void) {
    /* Initializing argument 1 (BufSize) */
    uword_t _BufSize = 1u;

    /* Tested function call */
    buf_t *_result = bufInit(_BufSize);
    CU_ASSERT_PTR_NOT_NULL(_result);
}



static void test_bufRev_0(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Tested function call */
    char_t _result = bufRev(_pBuf);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufRev_1(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = & _pBuf_0;

    /* Tested function call */
    char_t _result = bufRev(_pBuf);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufInit_4(void) {
    /* Initializing argument 1 (BufSize) */
    uword_t _BufSize = 0u;

    /* Tested function call */
    buf_t *_result = bufInit(_BufSize);
    CU_ASSERT_PTR_NULL(_result);
}



static void test_bufRevArray_0(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (Buf) */
    char_t *_Buf = 0;

    /* Initializing argument 3 (len) */
    word_t _len = 0;

    /* Tested function call */
    uword_t _result = bufRevArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufRevArray_1(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char_t *_Buf = 0;

    /* Initializing argument 3 (len) */
    word_t _len = 0;

    /* Tested function call */
    uword_t _result = bufRevArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufRevArray_2(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char _Buf_1 = 1;
    char_t *_Buf = &_Buf_1;

    /* Initializing argument 3 (len) */
    word_t _len = 0;

    /* Tested function call */
    uword_t _result = bufRevArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufRevArray_3(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char _Buf_1 = 0xFF;
    char_t *_Buf = &_Buf_1;

    /* Initializing argument 3 (len) */
    word_t _len = ~0;

    /* Tested function call */
    uword_t _result = bufRevArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufRevArray_4(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char _Buf_1 = 0;
    char_t *_Buf = &_Buf_1;

    /* Initializing argument 3 (len) */
    word_t _len = ~0;

    /* Tested function call */
    uword_t _result = bufRevArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufRevArray_5(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char _Buf_1 = 0;
    char_t *_Buf = &_Buf_1;

    /* Initializing argument 3 (len) */
    word_t _len = 0;

    uword_t _result = bufRevArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufRevArray_6(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (Buf) */
    char _Buf_0 = 0xFF;
    char_t *_Buf = &_Buf_0;

    /* Initializing argument 3 (len) */
    word_t _len = -1;

    /* Tested function call */
    uword_t _result = bufRevArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufRevArray_7(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char _Buf_1 = 0;
    char_t *_Buf = &_Buf_1;

    /* Initializing argument 3 (len) */
    word_t _len = -1;

    /* Tested function call */
    uword_t _result = bufRevArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufRevArray_8(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (Buf) */
    char _Buf_0 = 1;
    char_t *_Buf = &_Buf_0;

    /* Initializing argument 3 (len) */
    word_t _len = 1;

    /* Tested function call */
    uword_t _result = bufRevArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufRevArray_9(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char _Buf_1 = 0xFF;
    char_t *_Buf = &_Buf_1;

    /* Initializing argument 3 (len) */
    word_t _len = 0;

    /* Tested function call */
    uword_t _result = bufRevArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSend_0(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (ch) */
    char_t _ch = 0xFF;

    /* Tested function call */
    word_t _result = bufSend(_pBuf, _ch);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSend_1(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (ch) */
    char_t _ch  = 0xFF;

    /* Tested function call */
    word_t _result = bufSend(_pBuf, _ch);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSend_2(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t * _pBuf = 0;

    /* Initializing argument 2 (ch) */
    char_t _ch = 0;

    /* Tested function call */
    word_t _result = bufSend(_pBuf, _ch);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSend_3(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (ch) */
    char_t _ch = 0;

    /* Tested function call */
    word_t _result = bufSend(_pBuf, _ch);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSend_4(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (ch) */
    char_t _ch = 1;

    /* Tested function call */
    word_t _result = bufSend(_pBuf, _ch);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSend_5(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (ch) */
    char_t _ch = 1;

    /* Tested function call */
    word_t _result = bufSend(_pBuf, _ch);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSend_6(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (ch) */
    char_t _ch = 0;

    /* Tested function call */
    word_t _result = bufSend(_pBuf, _ch);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSend_7(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (ch) */
    char_t _ch = 0;

    /* Tested function call */
    word_t _result = bufSend(_pBuf, _ch);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSendArray_0(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (Buf) */
    const char_t *_Buf  = 0;

    /* Initializing argument 3 (len) */
    word_t _len = 0;

    /* Tested function call */
    uword_t _result  = bufSendArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSendArray_1(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    const char_t *_Buf = 0;

    /* Initializing argument 3 (len) */
    word_t _len = 0;

    /* Tested function call */
    uword_t _result  = bufSendArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSendArray_2(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (Buf) */
    char _Buf_0 = 0xFF;
    const char_t *_Buf = &_Buf_0;

    /* Initializing argument 3 (len) */
    word_t _len = 1;

    /* Tested function call */
    uword_t _result  = bufSendArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSendArray_3(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char _Buf_1 = 0xFF;
    const char_t *_Buf = &_Buf_1;

    /* Initializing argument 3 (len) */
    word_t _len = 1;

    /* Tested function call */
    uword_t _result  = bufSendArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSendArray_4(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (Buf) */
    char _Buf_0 = 0;
    const char_t *_Buf = &_Buf_0;

    /* Initializing argument 3 (len) */
    word_t _len = 1;

    /* Tested function call */
    uword_t _result = bufSendArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSendArray_5(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char _Buf_1 = 0;
    const char_t *_Buf = &_Buf_1;

    /* Initializing argument 3 (len) */
    word_t _len = 1;

    /* Tested function call */
    uword_t _result = bufSendArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSendArray_6(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (Buf) */
    char _Buf_0 = 1;
    const char_t *_Buf = &_Buf_0;

    /* Initializing argument 3 (len) */
    word_t _len = 1;

    /* Tested function call */
    uword_t _result = bufSendArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSendArray_7(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char _Buf_1 = 1;
    const char_t *_Buf = &_Buf_1;

    /* Initializing argument 3 (len) */
    word_t _len = 1;

    /* Tested function call */
    uword_t _result = bufSendArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSendArray_8(void) {
    /* Initializing argument 1 (pBuf) */
    buf_t *_pBuf = 0;

    /* Initializing argument 2 (Buf) */
    char _Buf_0 = 0;
    const char_t *_Buf = &_Buf_0;

    /* Initializing argument 3 (len) */
    word_t _len = 1;

    /* Tested function call */
    uword_t _result = bufSendArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}



static void test_bufSendArray_9(void) {
    /* Initializing argument 1 (pBuf) */
    struct buffer _pBuf_0 = {0};
    buf_t *_pBuf = &_pBuf_0;

    /* Initializing argument 2 (Buf) */
    char _Buf_1 = 0;
    const char_t *_Buf = &_Buf_1;

    /* Initializing argument 3 (len) */
    word_t _len = 1;

    /* Tested function call */
    uword_t _result = bufSendArray(_pBuf, _Buf, _len);
    CU_ASSERT_EQUAL(_result, 0);
}


static buf_t *buf = ((void*)0);
#define BUF_SIZE 32
static void test_buf_uniting(void) {
    char_t data_buf[BUF_SIZE];
    word_t len = -1;
    word_t i = 0;
    word_t re = 0;

    buf = bufInit(BUF_SIZE);
    CU_ASSERT_PTR_NOT_NULL(buf);


    len = bufGetUsed(buf);
    CU_ASSERT_EQUAL(len, 0);


    for(i=0; i<BUF_SIZE; i++) {
        re = bufSend(buf, i);
        CU_ASSERT_EQUAL(re, 1);
    }
    len = bufGetUsed(buf);
    CU_ASSERT_EQUAL(len, BUF_SIZE);

    for(i=0; i<BUF_SIZE; i++) {
        re = (word_t)bufRev(buf);
        CU_ASSERT_EQUAL(re, i);
    }
    len = bufGetUsed(buf);
    CU_ASSERT_EQUAL(len, 0);


    for(i=0; i<BUF_SIZE; i++) {
        data_buf[i] = i + 1;
    }
    len = bufSendArray(buf, data_buf, BUF_SIZE);
    len = bufGetUsed(buf);
    CU_ASSERT_EQUAL(len, BUF_SIZE);
    bufClear(buf);
    len = bufGetUsed(buf);
    CU_ASSERT_EQUAL(len, 0);

    for(i=0; i<BUF_SIZE; i++) {
        data_buf[i] = i;
    }
    bufSendArray(buf, data_buf, BUF_SIZE);
    len = bufGetUsed(buf);
    CU_ASSERT_EQUAL(len, BUF_SIZE);

    for(i=0; i<BUF_SIZE; i++) {
        data_buf[i] = 0;
    }
    re = bufRevArray(buf, data_buf, BUF_SIZE);
    CU_ASSERT_EQUAL(len, BUF_SIZE);
    len = bufGetUsed(buf);
    CU_ASSERT_EQUAL(len, 0);

    bufDel(buf);
}



int test_buf_init(void) {
    printf("Shared Buffer test ...\n\n");
    return 0;
}



int test_buf_clean(void) {
    printf("Shared Buffer test is over!\n\n");
    return 0;
}



CU_TestInfo test_buf_cases[] = {
    {"test_bufClear_0", test_bufClear_0},
    {"test_bufClear_1", test_bufClear_1},
    {"test_bufDel_0", test_bufDel_0},
    {"test_bufDel_1", test_bufDel_1},
    {"test_bufGetUsed_0", test_bufGetUsed_0},
    {"test_bufGetUsed_1", test_bufGetUsed_1},
    {"test_bufInit_0", test_bufInit_0},
    {"test_bufInit_1", test_bufInit_1},
    {"test_bufInit_2", test_bufInit_2},
    {"test_bufInit_3", test_bufInit_3},
    {"test_bufInit_4", test_bufInit_4},
    {"test_bufRev_0", test_bufRev_0},
    {"test_bufRev_1", test_bufRev_1},
    {"test_bufRevArray_0", test_bufRevArray_0},
    {"test_bufRevArray_1", test_bufRevArray_1},
    {"test_bufRevArray_2", test_bufRevArray_2},
    {"test_bufRevArray_3", test_bufRevArray_3},
    {"test_bufRevArray_4", test_bufRevArray_4},
    {"test_bufRevArray_5", test_bufRevArray_5},
    {"test_bufRevArray_6", test_bufRevArray_6},
    {"test_bufRevArray_7", test_bufRevArray_7},
    {"test_bufRevArray_8", test_bufRevArray_8},
    {"test_bufRevArray_9", test_bufRevArray_9},
    {"test_bufSend_0", test_bufSend_0},
    {"test_bufSend_1", test_bufSend_1},
    {"test_bufSend_2", test_bufSend_2},
    {"test_bufSend_3", test_bufSend_3},
    {"test_bufSend_4", test_bufSend_4},
    {"test_bufSend_5", test_bufSend_5},
    {"test_bufSend_6", test_bufSend_6},
    {"test_bufSend_7", test_bufSend_7},
    {"test_bufSendArray_0", test_bufSendArray_0},
    {"test_bufSendArray_1", test_bufSendArray_1},
    {"test_bufSendArray_2", test_bufSendArray_2},
    {"test_bufSendArray_3", test_bufSendArray_3},
    {"test_bufSendArray_4", test_bufSendArray_4},
    {"test_bufSendArray_5", test_bufSendArray_5},
    {"test_bufSendArray_6", test_bufSendArray_6},
    {"test_bufSendArray_7", test_bufSendArray_7},
    {"test_bufSendArray_8", test_bufSendArray_8},
    {"test_bufSendArray_9", test_bufSendArray_9},
    {"test_buf_uniting", test_buf_uniting},
    CU_TEST_INFO_NULL
};
